package com.jxlg.dao;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jxlg.bean.DOperator;

/**
 * A data access object (DAO) providing persistence and search support for
 * DOperator entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.jxlg.bean.DOperator
 * @author MyEclipse Persistence Tools
 */
public class DOperatorDAO extends BaseHibernateDAO
{
	private static final Logger log = LoggerFactory
			.getLogger(DOperatorDAO.class);
	// property constants
	public static final String UNITID = "unitid";
	public static final String CZYBH = "czybh";
	public static final String CZYXM = "czyxm";
	public static final String CZYMM = "czymm";
	public static final String LXDH = "lxdh";
	public static final String JB = "jb";
	public static final String IFCX = "ifcx";
	public static final String PIC = "pic";
	public static final String ZDTS = "zdts";

	public void save(DOperator transientInstance)
	{
		log.debug("saving DOperator instance");
		try
		{
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re)
		{
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(DOperator persistentInstance)
	{
		log.debug("deleting DOperator instance");
		try
		{
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re)
		{
			log.error("delete failed", re);
			throw re;
		}
	}

	public DOperator findById(java.lang.Integer id)
	{
		log.debug("getting DOperator instance with id: " + id);
		try
		{
			DOperator instance = (DOperator) getSession().get(
					"com.jxlg.bean.DOperator", id);
			return instance;
		} catch (RuntimeException re)
		{
			log.error("get failed", re);
			throw re;
		}
	}

	public List<?> findByExample(DOperator instance)
	{
		log.debug("finding DOperator instance by example");
		try
		{
			List<?> results = getSession()
					.createCriteria("com.jxlg.bean.DOperator")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re)
		{
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List<?> findByProperty(String propertyName, Object value)
	{
		log.debug("finding DOperator instance with property: " + propertyName
				+ ", value: " + value);
		try
		{
			String queryString = "from DOperator as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re)
		{
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<?> findByUnitid(Object unitid)
	{
		return findByProperty(UNITID, unitid);
	}

	public List<?> findByCzybh(Object czybh)
	{
		return findByProperty(CZYBH, czybh);
	}

	public List<?> findByCzyxm(Object czyxm)
	{
		return findByProperty(CZYXM, czyxm);
	}

	public List<?> findByCzymm(Object czymm)
	{
		return findByProperty(CZYMM, czymm);
	}

	public List<?> findByLxdh(Object lxdh)
	{
		return findByProperty(LXDH, lxdh);
	}

	public List<?> findByJb(Object jb)
	{
		return findByProperty(JB, jb);
	}

	public List<?> findByIfcx(Object ifcx)
	{
		return findByProperty(IFCX, ifcx);
	}

	public List<?> findByPic(Object pic)
	{
		return findByProperty(PIC, pic);
	}

	public List<?> findByZdts(Object zdts)
	{
		return findByProperty(ZDTS, zdts);
	}

	public List<?> findAll()
	{
		log.debug("finding all DOperator instances");
		try
		{
			String queryString = "from DOperator";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re)
		{
			log.error("find all failed", re);
			throw re;
		}
	}

	public DOperator merge(DOperator detachedInstance)
	{
		log.debug("merging DOperator instance");
		try
		{
			DOperator result = (DOperator) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re)
		{
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(DOperator instance)
	{
		log.debug("attaching dirty DOperator instance");
		try
		{
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re)
		{
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(DOperator instance)
	{
		log.debug("attaching clean DOperator instance");
		try
		{
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re)
		{
			log.error("attach failed", re);
			throw re;
		}
	}

	public DOperator findByCzybh(String czybh)
	{
		String hsql = "from DOperator u where u.czybh=?";
		Query query = (Query) this.getSession().createQuery(hsql);
		query.setString(0, czybh);
		DOperator result = (DOperator) query.uniqueResult();
		return result;
	}

	
}
